import Vue from 'vue';
import Router from 'vue-router';
import home from '@/router/pages/home.vue'; //首页(布局页面)
import $store from '@/store'; // 应用vuex

// 页面板块
import performanceAppraisal from './pages/performanceAppraisal/index.js'; //绩效考核板块
import setUp from './pages/setUp/index.js'; //设置板块
import submissionInfo from './pages/submissionInfo/index.js'; //提交信息

Vue.use (Router);

const router = new Router ({
  routes: [
    {
      path: '/',
      name: 'home',
      component: home,
      children: [...performanceAppraisal, ...setUp, ...submissionInfo],
    },
  ],
});

router.beforeEach (async (to, from, next) => {
  // 动态设置标题
  const {title} = to.meta;
  if (typeof document !== 'undefined') document.title = title || '考核系统';

  const routes = router.options.routes;
  // console.log(routes);

  //我可以看见的全部页面可以在这里进行权限控制等
  $store.state.router.myRoutes = routes[0];

  // 权限验证
  // if (await auth (to, next, router, from)) return;
  // if (await dingtalk (to, next, router, from)) return;

  next ();
});

router.afterEach (() => {});

export default router;
